package gagak.framework.web.handler;

import gagak.framework.web.reflect.AnnotationAttributes;
import org.apache.commons.collections.MapUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/*
 * @program: ce
 * @description: 控制器元属性
 * @author: houhong
 * @create: 2022-11-23 16:27
 */
public class ControllerHandler {

    /*
     * 路径
     */
    private volatile String path;

    /*
     * 控制器类型
     */
    private Class<?> controllerType;

    /*
     * 控制器
     */
    private volatile Object controller;

    /*
     * 方法列表
     */
    private List<Method> methodList;

    /*
     * 控制器类上面注解属性
     */
    private Map<Annotation, AnnotationAttributes> annotationAttributesMap;

    public ControllerHandler() {
    }

    public ControllerHandler(Class<?> controllerType) {
        this.controllerType = controllerType;
    }

    public ControllerHandler(Class<?> controllerType,
                             Map<Annotation, AnnotationAttributes> annotationAttributesMap) {

        this(controllerType);
        this.annotationAttributesMap = annotationAttributesMap;
    }

    public ControllerHandler(Class<?> controllerType, List<Method> methodList,
                             Map<Annotation, AnnotationAttributes> annotationAttributesMap) {

        this(controllerType, annotationAttributesMap);
        this.methodList = methodList;
    }

    public ControllerHandler(Class<?> controllerType,
                             Object controller,
                             List<Method> methodList,
                             Map<Annotation, AnnotationAttributes> annotationAttributesMap) {

        this(controllerType, methodList, annotationAttributesMap);
        this.controller = controller;
    }


    public ControllerHandler(String path, Class<?> controllerType,
                             Object controller,
                             List<Method> methodList,
                             Map<Annotation, AnnotationAttributes> annotationAttributesMap) {

        this(controllerType, controller, methodList, annotationAttributesMap);
        this.path = path;
    }





    public Class<?> getControllerType() {
        return controllerType;
    }

    public void setControllerType(Class<?> controllerType) {
        this.controllerType = controllerType;
    }

    public List<Method> getMethodList() {
        return methodList;
    }

    public void setMethodList(List<Method> methodList) {
        this.methodList = methodList;
    }

    public Map<Annotation, AnnotationAttributes> getAnnotationAttributesMap() {
        return annotationAttributesMap;
    }

    public void setAnnotationAttributesMap(Map<Annotation, AnnotationAttributes> annotationAttributesMap) {
        this.annotationAttributesMap = annotationAttributesMap;
    }




    public void addAnnotationAttributesMap(Annotation annotation, AnnotationAttributes
            annotationAttributes) {

        if (MapUtils.isEmpty(this.annotationAttributesMap)) {
            this.annotationAttributesMap = new LinkedHashMap<Annotation, AnnotationAttributes>(8);
        }
        this.annotationAttributesMap.put(annotation, annotationAttributes);
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public Object getController() {
        return controller;
    }

    public void setController(Object controller) {
        this.controller = controller;
    }
}